<template>
  <el-dialog draggable overflow :title="titleMap[mode]" v-model="visible" :width="400" destroy-on-close
    @closed="$emit('closed')">
    <el-tabs type="border-card">
      <el-tab-pane ref="tab" label="基础信息">
        <el-form :model="form" :rules="rules" ref="dialogForm" label-width="70px">
          <el-row>

            <el-col :span="24">
              <el-form-item label="运输商" prop="company_id">
                <skAutoChoose v-model="form.company.name" :name="'factory'" :asKey="'company_id'" :assign="form"
                  :params="[{ category_id: 54 }]">
                </skAutoChoose>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="金额" prop="amount">
                <el-input v-model="form.amount" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" clearable></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>

    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import skDicSelect from "@/components/skDicSelect";
import skAutoChoose from "@/components/skAutoChoose";
import tool from '@/utils/tool';
export default {
  emits: ["success", "closed"],
  components: { skDicSelect, skAutoChoose },
  data() {
    return {
      mode: "edit",
      openChoose: {
        order: false,
        storage: false,
      },

      gridOps: {
        height: 300,
        columns: [
          {
            field: "material.name",
            event: {
              select: ({ e, row }) => {
                row["material"]["spec"] = e.spec;
              },
            },
          },
          {
            field: "color.name",
            event: {
              select: ({ e, row }) => {
                row["color"]["code"] = e.code;
              },
            },
          },
          {
            field: "auxiliary_quantity",
            event: {
              keyup: ({ row }) => {
                row["quantity"] = row["auxiliary_quantity"] * 25;

              },
            },
          },
        ],
      },
      titleMap: {
        add: "新增",
        edit: "编辑",
      },

      form: {
        id: "",
        code: "",
        company: {
          name: "",
        },
        department: {},
        details: [],
        billdate: tool.SYS_DATE()
      },
      rules: {
        company_id: [{ required: true, message: "运输商必填" }],
      },
      visible: false,
      isSaveing: false,
    };
  },
  mounted() { },
  methods: {
    //显示
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },

    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;

          var res = await this.$API.comprehensive.car.save.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          } else {
            this.$alert(res.message, "提示", { type: "error" });
          }
        }
      });
    },
  },
};
</script>

<style></style>
